#include "TCP.h"

TCP::TCP()
{}

int TCP::parse(Packet* pkt)
{
	if(sizeof(TCP_Header) >= pkt->pktLength - pkt->parsePos)                              
	{
		pkt->state = STATE_FAIL;                                         
		return -1;
	}

	uint8_t* data = pkt->rawPkt + pkt->parsePos;

	TCP_Header* header = (TCP_Header*)data;

	//	printf("srcPort = %d, dstPort = %d\n", ntohs(header->srcPort), ntohs(header->dstPort));

	pkt->parsePos += (header->headerLength >> 4 & 0x0f) * 4;

	if(80 == ntohs(header->srcPort) || 80 == ntohs(header->dstPort))
	{
		pkt->state = STATE_HTTP;
	}
	else
	{
		pkt->state = STATE_FAIL;
	}

	return 0;
}
